package com.stars.icp.utils;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

/**
 * @author starts
 */
public class ObjectUtils {
    public static boolean isEmpty(Object object) {
        if (object == null) {
            return true;
        } else if (object instanceof CharSequence) {
            return ((CharSequence)object).length() == 0;
        } else if (isArray(object)) {
            return Array.getLength(object) == 0;
        } else if (object instanceof Collection) {
            return ((Collection)object).isEmpty();
        } else if (object instanceof Map) {
            return ((Map)object).isEmpty();
        } else if (object instanceof Optional) {
            return !((Optional)object).isPresent();
        } else {
            return false;
        }
    }

    public static boolean isArray(Object object) {
        return object != null && object.getClass().isArray();
    }
}
